import 'package:flutter/material.dart';
import 'package:flutter_appdemo02/page/HttpPage.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_appdemo02/page/LoveAwesome.dart';
import 'package:flutter_appdemo02/page/Onboarding.dart';
import 'package:flutter_appdemo02/page/One.dart';
import 'package:flutter_appdemo02/page/Tab.dart';
import 'package:flutter_appdemo02/page/huadong.dart';
import 'package:flutter_appdemo02/page/screetest.dart';
import 'package:flutter_appdemo02/page/sqlite.dart';

import 'CupertinoSegmentedControlDemo.dart';
import 'Hello.dart';
import 'HuaDong02.dart';
import 'MyHomePage.dart';
import 'Personal.dart';
import 'ProviderTest.dart';
import 'Test01.dart';
import 'Three.dart';
import 'Two.dart';
import 'Waterfalls.dart';
import 'flutter_slidable.dart';
import 'flutter_slidable_2.dart';
import 'flutter_slidable_3.dart';

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  ScrollController _controller = new ScrollController();
  bool showToTopBtn = false; //是否显示“返回到顶部”按钮

  @override
  void initState() {
    super.initState();
    //监听滚动事件，打印滚动位置
    _controller.addListener(() {
      if (_controller.offset < 1 && showToTopBtn) {
        setState(() {
          showToTopBtn = false;
        });
      } else if (_controller.offset >= 10 && showToTopBtn == false) {
        setState(() {
          showToTopBtn = true;
        });
      }
    });
  }

  @override
  void dispose() {
    //为了避免内存泄露，需要调用_controller.dispose
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 1080, height: 2334)..init(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("demo"),
        actions: <Widget>[
          GestureDetector(
            child: Icon(Icons.edit),
            onTap: () {},
          ),
        ],
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: ListView(
          controller: _controller,
          children: <Widget>[
            ListTile(
              leading: CircleAvatar(
                backgroundImage: NetworkImage(
                    "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21589.jpg"),
              ),
              title: Text("测试"),
              onTap: () {
                Navigator.of(context).push(
                    MaterialPageRoute(builder: (context) => MyHomePage()));
              },
            ),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21588.jpg"),
                ),
                title: Text("scree"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => ScreePage()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21587.jpg"),
                ),
                title: Text("sqltest"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => SqliteExample()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21586.jpg"),
                ),
                title: Text("瀑布流"),
                onTap: () {
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => WaterfallsPage()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21585.jpg"),
                ),
                title: Text("测试"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => Example07()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("tab"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => Tabs()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21583.jpg"),
                ),
                title: Text("one"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => OnePage()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21596.jpg"),
                ),
                title: Text("two"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => TwoPage()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21593.jpg"),
                ),
                title: Text("赞"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => LoveAwesome()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("引导页"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => Onboarding()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21597.jpg"),
                ),
                title: Text("界面"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => Personal()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pic2.sc.chinaz.com/Files/pic/pic9/201909/bpic13672.jpg"),
                ),
                title: Text("屏幕滑动"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => HuaDong()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pic1.sc.chinaz.com/Files/pic/pic9/201911/zzpic21376.jpg"),
                ),
                title: Text("Hello"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => Hello()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pic1.sc.chinaz.com/Files/pic/pic9/201911/zzpic21376.jpg"),
                ),
                title: Text("屏幕滑动02"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => Huadong02()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pic1.sc.chinaz.com/Files/pic/pic9/201911/zzpic21376.jpg"),
                ),
                title: Text("images pick"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => Three()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("ios风格"),
                onTap: () {
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => CupertinoSegmentedControlDemo()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("Post请求"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => HttpPage()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("providertest"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => MyApp()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("flutterslidable"),
                onTap: () {
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => flutterslidable()));
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("flutterslidable2"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => MyHomePage2())
                  );
                }),
            Divider(),
            ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(
                      "http://pics.sc.chinaz.com/files/pic/pic9/201912/zzpic21591.jpg"),
                ),
                title: Text("flutterslidable3"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => MyHomePage3()));
                }),
          ],
        ),
      ),

      // Drawer
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("测试"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => MyHomePage()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("scree"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => ScreePage()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("sqltest"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => SqliteExample()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("瀑布流"),
                onTap: () {
                  Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => WaterfallsPage()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("测试"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => Example07()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("tab"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => Tabs()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("one"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => OnePage()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("two"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => TwoPage()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("赞"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => LoveAwesome()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("引导页"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => Onboarding()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("界面"),
                onTap: () {
                  Navigator.of(context).push(
                      MaterialPageRoute(builder: (context) => Personal()));
                }),
            ListTile(
                leading: Icon(Icons.edit_attributes),
                title: Text("屏幕滑动"),
                onTap: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) => HuaDong()));
                })
          ],
        ),
      ),

      floatingActionButton: !showToTopBtn
          ? null
          : FloatingActionButton(
              child: Icon(Icons.arrow_upward),
              onPressed: () {
                _controller.animateTo(.0,
                    duration: Duration(milliseconds: 200), curve: Curves.ease);
              },
            ),
    );
  }
}
